#line 1 "D:/Archivio/mikroC/tric-ricotta/lib_itg3200.c"
#line 1 "d:/archivio/mikroc/tric-ricotta/lib_itg3200.h"
#line 11 "d:/archivio/mikroc/tric-ricotta/lib_itg3200.h"
void ITG3200_init();
void ITG3200_readGyro(float *gyro);
#line 7 "D:/Archivio/mikroC/tric-ricotta/lib_itg3200.c"
void ITG3200_init() {
 unsigned short temp;


 I2C1_Start();
 I2C1_Wr( 0xD2 );
 I2C1_Wr(0x3E);
 I2C1_Stop();
 I2C1_Start();
 I2C1_Wr( 0xD3 );
 temp = I2C1_Rd(0);
 I2C1_Stop();
 I2C1_Start();
 I2C1_Wr( 0xD2 );
 I2C1_Wr(0x3E);
 I2C1_Wr(((temp & 0xF1) | 0x03));
 I2C1_Stop();
 Delay_ms(50);


 I2C1_Start();
 I2C1_Wr( 0xD2 );
 I2C1_Wr(0x15);
 I2C1_Wr(0x01);
 I2C1_Stop();
 Delay_ms(10);


 I2C1_Start();
 I2C1_Wr( 0xD2 );
 I2C1_Wr(0x16);
 I2C1_Wr(0x1D);
 I2C1_Stop();
 Delay_ms(10);
}

void ITG3200_readGyro(float *gyro) {
 unsigned short cnt;
 unsigned short gyro_read[6];
 int gyro_int[3];

 I2C1_Start();
 I2C1_Wr( 0xD2 );
 I2C1_Wr(0x1D);
 I2C1_Stop();
 I2C1_Start();
 I2C1_Wr( 0xD3 );
 for (cnt=0; cnt<6; cnt++) {
 char ack;
 ack = (cnt<5);
 gyro_read[cnt] = I2C1_Rd(ack);
 }
 I2C1_Stop();

 gyro_int[0] = gyro_read[0];
 gyro_int[0] = gyro_int[0] << 8;
 gyro_int[0] |= gyro_read[1];
 gyro_int[1] = gyro_read[2];
 gyro_int[1] = gyro_int[1] << 8;
 gyro_int[1] |= gyro_read[3];
 gyro_int[2] = gyro_read[4];
 gyro_int[2] = gyro_int[2] << 8;
 gyro_int[2] |= gyro_read[5];

 gyro[0] = (float)(gyro_int[0] / 14.375);
 gyro[1] = (float)(gyro_int[1] / 14.375);
 gyro[2] = (float)(gyro_int[2] / 14.375);
}
